﻿namespace OpenCompiler.AST
{
	public class VisibilityStatement<T> : ModifierStatement<T>
		where T : class
	{
		public bool IsPublic { get; private set; }
		public bool IsPrivate { get; private set; }
		public bool IsPartial { get; private set; }
		public bool IsInternal { get; private set; }
		public bool IsProtected { get; private set; }

		internal VisibilityStatement(Statement parent, string name)
			: base(parent, name)
		{
		}


		public T FromModifierState()
		{
			this.IsPublic = ModifierState.IsPublic;
			this.IsPartial = ModifierState.IsPartial;
			this.IsInternal = ModifierState.IsInternal;
			this.IsProtected = ModifierState.IsProtected;
			this.IsPrivate = ModifierState.IsPrivate;
			return this as T;
		}

		public T Public()
		{
			this.IsPublic = true;
			return this as T;
		}

		public T Partial()
		{
			this.IsPartial = true;
			return this as T;
		}

		public T Internal()
		{
			this.IsInternal = true;
			return this as T;
		}

		public T Protected()
		{
			this.IsProtected = true;
			return this as T;
		}

		public T Private()
		{
			this.IsPrivate = true;
			return this as T;
		}

		public override string ToString()
		{
			var str = string.Empty;
			if (this.IsPublic)
			{
				str += "public";
			}
			str = this.AddSpace(str);
			if (this.IsPartial)
			{
				str += "partial";
			}
			str = this.AddSpace(str);
			if (this.IsProtected)
			{
				str += "protected";
			}
			str = this.AddSpace(str);
			if (this.IsInternal)
			{
				str += "internal";
			}
			str = this.AddSpace(str);
			if( this.IsPrivate )
			{
				str += "private";
			}
			str = this.AddSpace(str);

			return str;
		}
	}
}
